import { ColumnProps, verifySpecialValuesProps } from "../interface";

export const useOtherStyle = (labelWidth, specialValue, verifySpecialValues: verifySpecialValuesProps[]) => {
  const labelStyle = () => {
    return {
      width: labelWidth + "rpx"
    };
  };

  const valueStyle = (head: ColumnProps, item) => {
    let specialFieldStyle = {};
    if (specialValue) {
      const v = specialValue.split(",");

      const flag = verifyValue(verifySpecialValues, item, head);
      if (flag && v.includes(head.prop)) {
        specialFieldStyle = {
          fontWeight: "bold",
          color: useThemeStore().basicColor.primary
        };
      }
    }
    return {
      width: `calc(100% - ${labelWidth}rpx)`,
      ...specialFieldStyle
    };
  };

  /**
   * @description: 特殊值 是否显示特殊颜色
   * @param {verifySpecialValuesProps} verifySpecialValues
   * @return {*}
   */
  const verifyValue = (verifySpecialValues: verifySpecialValuesProps[], item, head: ColumnProps) => {
    if (!verifySpecialValues?.length) return true;
    for (let son of verifySpecialValues) {
      if (head.prop === son.prop) {
        return !son.excludeValue.includes(item[son.prop]);
      }
    }
  };

  // 最后一行样式
  const rowLastClass = (key, columns) => {
    if (key === columns.length - 1) return "last-row";
  };

  const setScrollStyle = (height: number) => {
    return setScrollHeight(height);
  };

  return {
    labelStyle,
    valueStyle,
    rowLastClass,
    setScrollStyle
  };
};
